



/*

Dofile: table1_appendix.do 

Date: Dec. 10, 2016 
Aim: Stat des on kept and dropped transactions  

Input: base_for_reg.dta 
Output: table1_appendix.dta 
Reported in the paper: "Table A.1: Dropped vs kept transactions across HS4 codes"

*/  

cd $datapath
use desc_x, clear


*** drop if firm has an affiliate or a headquarter according to LiFi but do not do intrafirm
drop if export==0
replace intra_x=0 if intra_x==. 
g type=0 
replace type=2 if intra_x>$lowerbound
replace related=related==1
tab type related
drop if type==0 & related==1 

*** we drop obs of indep firms according to LIFI that do intrafirm 
replace type=1 if intra_x>$upperbound
drop if natact=="0" & max>0
drop if natact=="2"



*** stat des on HS4-destinations we drop 
save temp1, replace 
collapse (sum) export intra_x, by(type siren hs4 pays)
g mne_=type>0  
egen mne=max(mne_), by(siren) 
egen t1=group(siren)
sum t1
keep if mne==1 
egen t2=group(siren)
sum t2 
egen max=max(type), by(siren) 
egen t3=group(siren) if max==2
sum t3 
drop t1 t2 t3
g drop=type==2
egen nb_drop=sum(drop), by(siren) 
egen nb=count(drop), by(siren)
sum nb*, d 
sum nb* if max==2
collapse (sum) export , by(max drop siren)
fillin siren drop
replace drop=0 if drop==.
replace export=0 if export==.
egen tot=sum(export), by(siren) 
g sh=export/tot 
bys drop: sum export, d
sum sh if drop==0, d

use temp1, replace 
collapse (sum) export, by(hs4 type) 
egen tot=sum(export), by(hs4) 
replace type=type+1 
reshape wide export, i(hs4 to) j(type)
forvalue i=1/3{
egen tot`i'=sum(export`i') 
g sh`i'=export`i'/tot`i'
}
forvalue i=1/3{
replace sh`i'=0 if sh`i'==.
}
egen t=sum(tot)
g sh=tot/t 
gsort - sh3 
br hs4 sh*


